package com.yanqu.road.server.cmd.assistant.assistantSkin;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.assistant.AssistantSkinProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.assistant.AssistantSkinModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ASSISTANT_UPGRADE_DECORATION, desc = "升级或解锁小助理装扮")
public class UpgradeAssistantDecorationCmd extends AbstractCommand {
    int decorationId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AssistantSkinProto.AssistantUpgradeDecorationReqMsg msg = AssistantSkinProto.AssistantUpgradeDecorationReqMsg.parseFrom(packet.getBytes());
        decorationId = msg.getDecorationId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(AssistantSkinModule.class).upgradeAssistantDecoration(decorationId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            AssistantSkinProto.AssistantUpgradeDecorationRespMsg.Builder builder = AssistantSkinProto.AssistantUpgradeDecorationRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_ASSISTANT_UPGRADE_DECORATION_RESULT, builder);
        }
    }
}
